$(function() {
	var contractIds;
	//证件类型初始化
	initTypeid();
	loadingNewData();
	
	if($("#labels").val() == "1"){//新业务照会
		var policeRefUrl = GetQueryString("policeRef");
		if(policeRefUrl !=null && policeRefUrl.toString().length>1){
			window.onload = queryGoing(policeRefUrl);
		}else{
			window.onload = queryGoing();
		}
		//查询
		$("#queryGo").click(function(){
			queryGoing();
		});
	}
	//保全照会
	if($("#labels").val() == "2"){
		var policeRefUrl = GetQueryString("policeRef");
		if(policeRefUrl !=null && policeRefUrl.toString().length>1){
			window.onload = queryGoing(policeRefUrl);
		}else{
			window.onload = queryGoing();
		}
		//查询
		$("#queryGo").click(function(){
			queryGoing();
		});
	}
	
	//新单回访照会
	if($("#labels").val() == "3"){
		var policeRefUrl = GetQueryString("policeRef");
		if(policeRefUrl !=null && policeRefUrl.toString().length>1){
			window.onload = queryGoing(policeRefUrl);
		}else{
			window.onload = queryGoing();
		}
		//查询
		$("#queryGo").click(function(){
			queryGoing();
		});
	}
	
	//理赔照会
	if($("#labels").val() == "4"){
		var policeRefUrl = GetQueryString("policeRef");
		if(policeRefUrl !=null && policeRefUrl.toString().length>1){
			window.onload = queryGoing(policeRefUrl);
		}else{
			window.onload = queryGoing();
		}
		//查询
		$("#queryGo").click(function(){
			queryGoing();
		});
	}

	//质检照会
	if($("#labels").val() == "5"){
		var policeRefUrl = GetQueryString("policeRef");
		if(policeRefUrl !=null && policeRefUrl.toString().length>1){
			window.onload = queryGoing(policeRefUrl);
		}else{
			window.onload = queryGoing();
		}
		//查询
		$("#queryGo").click(function(){
			queryGoing();
		});
	}
	
	
});




//htmlNull
function htmlNull(){
	var htmlNull = '';
	htmlNull+='<tr class="noFind">';
	htmlNull+='<td colspan="6">暂无符合条件的查询</td>';
	htmlNull+='</tr>';
	$("#tableSort tbody tr").remove();
	$("#tableSort tbody").append(htmlNull);
};

//保单号补全
$("#policyNumber").blur(function(obj) {
    var v=this.value;
    if(v.length == 12 || v.length <=0){
    	return;
    }else{
        while(v.length<12){v='0'+v;}this.value=v;
    }
});

//重置
$("#Reset").click(function(){
	$("#policyNumber").attr("value",""); 		//保单号
	$("#PolicyHolder").attr("value",""); 		//投保人
	$("#CertificateNumber").attr("value",""); 	//投保人证件号码
	var a = document.getElementById("typeId"); 	//投保人证件类型
	a.options[0].selected = true;
	//$("#tableSort tr:gt(0)").remove(); 			//查询前清空数据
	$("#demanded").parent().addClass('hide');
	
	//升序降序重置
	$(".primary th").find(".icon_1").text("↑");
	
});

//正序倒序
$.extend($,{
    //命名空间
    sortTable:{
        sort:function(tableId,Idx){
            var table = document.getElementById(tableId);
            var tbody = table.tBodies[0];
            var tr = tbody.rows;
    
            var trValue = new Array();
            for (var i=0; i<tr.length; i++ ) {
                trValue[i] = tr[i];  //将表格中各行的信息存储在新建的数组中
            }
    
            if (tbody.sortCol == Idx) {
                trValue.reverse(); //如果该列已经进行排序过了，则直接对其反序排列
            	iconUp(Idx)
            } else {
                //trValue.sort(compareTrs(Idx));  //进行排序
                trValue.sort(function(tr1, tr2){
                    var value1 = tr1.cells[Idx].innerHTML;
                    var value2 = tr2.cells[Idx].innerHTML;
                    return value1.localeCompare(value2);
                });
            }
    
            var fragment = document.createDocumentFragment();  //新建一个代码片段，用于保存排序后的结果
            for (var i=0; i<trValue.length; i++ ) {
                fragment.appendChild(trValue[i]);
            }
    
            tbody.appendChild(fragment); //将排序的结果替换掉之前的值
            tbody.sortCol = Idx; 
            
            //检测排序方向
            function iconUp(Idx){
            	var text = $(".primary th").eq(Idx).find(".icon_1").text();
            	var test =  $(".primary th").eq(Idx).siblings().find(".icon_1");
            	if(text=="↑"){
            		$(".primary th").eq(Idx).find(".icon_1").text("↓");
            		test.text("↑");
            	}
            	else{
            		$(".primary th").eq(Idx).find(".icon_1").text("↑");
            	}
            }

        }
    }
})



//证件
var initTypeid = function(){
	$("#typeId").html("");
	var html="";
	html +='<option value="">'+'请选择'+'</option>';
	html +='<option value="National ID">'+'身份证'+'</option>';
	html +='<option value="Passport">'+'护照'+'</option>';
	html +='<option value="Military ID">'+'军官证'+'</option>';
	html +='<option value="Residence Book">'+'户口本'+'</option>';
	html +='<option value="Birth Card">'+'出生证'+'</option>';
	$("#typeId").append(html);
}

//无数据显示空白
function noData(){
	for(var j=0;j<$("#tableSort tbody td").length;j++){
		if($("#tableSort tbody td").eq(j).text()=="undefined"){
			$("#tableSort tbody td").eq(j).text("");
		}
	}
}


//投保人模糊查询
function handleData(one,result) {
    var jsonParam= {};
    jsonParam.phName = $("#PolicyHolder").val();
    if($("#labels").val() == "1"){
		padMarketing.ajaxNormal(//新业务照会
	    '/pad_marketing/notes/getFuSearch.action',jsonParam,
	    function(data) {
	    	$("#"+one+"").html("");
	    	var name = $("#"+result+"").val();
	    	if(!name){
	    		return;
	    	}
			var htmlMh = "";
			if(data != "" ){
		        htmlMh +='<li style="cursor:pointer" onClick="inputsThis(this)" >'+data+'</li>';
			}

	        $("#searchInput").append(htmlMh);
	    },
	    function(data){},
	    true,false);
    }
    if($("#labels").val() == "2"){
		padMarketing.ajaxNormal(//保全照会
	    '/pad_marketing/notes/getPolicyFuzzyMantenList.action',jsonParam,
	    function(data) {
	    	console.log(data);
	    	$("#"+one+"").html("");
	    	var name = $("#"+result+"").val();
	    	if(!name){
	    		return;
	    	}
			var htmlMh = "";
			if(data != "" ){
		        htmlMh +='<li style="cursor:pointer" onClick="inputsThis(this)" >'+data+'</li>';
			}

	        $("#searchInput").append(htmlMh);
	    },
	    function(data){},
	    true,false);
    }
    if($("#labels").val() == "3"){
		padMarketing.ajaxNormal(//新单回访照会
	    '/pad_marketing/notes/getFuzzyPolicyReturnVisit.action',jsonParam,
	    function(data) {
	    	console.log(data);
	    	$("#"+one+"").html("");
	    	var name = $("#"+result+"").val();
	    	if(!name){
	    		return;
	    	}
			var htmlMh = "";
			if(data != "" ){
		        htmlMh +='<li style="cursor:pointer" onClick="inputsThis(this)" >'+data+'</li>';
			}

	        $("#searchInput").append(htmlMh);
	    },
	    function(data){},
	    true,false);
    }
    if($("#labels").val() == "4"){
		padMarketing.ajaxNormal(//理赔照会
	    '/pad_marketing/notes/getFuzzyClaimList.action',jsonParam,
	    function(data) {
	    	console.log(data);
	    	$("#"+one+"").html("");
	    	var name = $("#"+result+"").val();
	    	if(!name){
	    		return;
	    	}
			var htmlMh = "";
			if(data != "" ){
		        htmlMh +='<li style="cursor:pointer" onClick="inputsThis(this)" >'+data+'</li>';
			}

	        $("#searchInput").append(htmlMh);
	    	
	    },
	    function(data){},
	    true,false);
    }
    if($("#labels").val() == "5"){
		padMarketing.ajaxNormal(//质检照会
	    '/pad_marketing/notes/getFuzzyQualityList.action',jsonParam,
	    function(data) {
	    	console.log(data);
	    	$("#"+one+"").html("");
	    	var name = $("#"+result+"").val();
	    	if(!name){
	    		return;
	    	}
			var htmlMh = "";
			if(data != "" ){
		        htmlMh +='<li style="cursor:pointer" onClick="inputsThis(this)" >'+data+'</li>';
			}

	        $("#searchInput").append(htmlMh);
	    	
	    },
	    function(data){},
	    true,false);
    }
}
function inputsThis(me){
	var obj = $(me).text();
	$("#PolicyHolder").val(obj);
	$("#searchInput").html("");
}


//清除模糊查询
function clearPerson(){
	setTimeout(function(){
		$("#searchInput").remove();
	},100);	
}


//新业务存储参数
function sessionData(c){
	var oiu = JSON.parse($(c).parent().parent("#dataAll").attr("data"));
	sessionStorage.contractId = oiu.CONTRACT_ID; //保单内部IT
	sessionStorage.policyRef = oiu.POLICY_REF;	//保单号
	sessionStorage.productName = oiu.ABBR_NAME;    //主险名称
	goNexthtml();
}

//新业务照会及质检照会跳转页面
function goNexthtml(){
	thisUrl = window.document.location.pathname;//当前URL
	if(thisUrl != '/pad_marketing/notes/myNote_5.action'){
		window.location = "/pad_marketing/note/noteContent.action?Url="+encodeURIComponent(thisUrl);			//新业务照会           
	}else{
		window.location = "/pad_marketing/qualityCheck/noteDetailQC.action?Url="+encodeURIComponent(thisUrl);	//质检照会
	}
	
}

//新单回访pdf展示
function goNewPdf(p){
	var oiuPdf = JSON.parse($(p).parent().parent("#dataAll").attr("data"));
	var jsonParam={};
	jsonParam.policyRef = oiuPdf.POLICY_REF;
	console.log(jsonParam)
	padMarketing.ajaxNormal(
	'/pad_marketing/notes/getPDFUrl.action',jsonParam,
	function(data) {
		console.log(data)
		var letterParams = data[0].LETTER_PARAMS;
		//调壳弹出新页面，参数说明：1：回调函数名称，2：要展示的地址，3：回调函数参数，4：是否需要签字
		gotoPDF('pdfRefresh',letterParams,0,'N');
	},
	function(data){})//调用失败结果
	
}

//保全PDF展示
function goNewPdf2(c){
	thisUrl = window.document.location.pathname;//当前URL
	if(thisUrl == '/pad_marketing/notes/myNote_2.action'){
		//保全照会URL
		var oiuPdf = JSON.parse($(c).parent().parent("#dataAll").attr("data"));
		var noticeId = oiuPdf.NOTICE_ID;
		var contractId = oiuPdf.CONTRACT_ID;
		//sign获取
		var signKey = String(contractId)+noticeId+"NEWTOUCH";
		$.ajax({
		  url: '/pad_marketing/main/getSign.action',
		  data: {'jsonParam':JSON.stringify({signKey:signKey})},
		  success: function(data){
			  sign = data.sign;
			  address = data.address;
		  },
		  async:false
		}); 
		var pdfUrl = address+"/POSNotice?contractId="+contractId+"&noticeId="+noticeId+"&partner=NEWTOUCH&sign="+sign;
//		var pdfUrl = "http://portal.allianz.com.cn/portal/Interface/iPad/POSNotice?contractId=32160&noticeId=21&partner=NEWTOUCH&sign=0CF620C091342D7E24C2A0CB818A7E8D"
		
	}else{
		//理赔照会URL
		var oiuPdf = JSON.parse($(c).parent().parent("#dataAll").attr("data"));
		var noticeId = oiuPdf.NOTICE_ID;
		var contractId = oiuPdf.CONTRACT_ID;
		//sign获取
		var signKey = noticeId+"NEWTOUCH";
		$.ajax({
		  url: '/pad_marketing/main/getSign.action',
		  data: {'jsonParam':JSON.stringify({signKey:signKey})},
		  success: function(data){
			  sign = data.sign;
			  address = data.address;
		  },
		  async:false
		}); 
		var pdfUrl = address+"/CN0001?noticeId="+noticeId+"&partner=NEWTOUCH&sign="+sign;
//		var pdfUrl = "http://portal.allianz.com.cn/portal/Interface/iPad/CN0001?noticeId=136&partner=NEWTOUCH&sign=7CB926AB770A03F6D1DBA19F6D6211F7"
	}
	
	//调壳弹出新页面，参数说明：1：回调函数名称，2：要展示的地址，3：回调函数参数，4：是否需要签字
	gotoPDF('pdfRefresh',pdfUrl,0,'N');
	
}

//数据汇总
function loadingNewData(){
	padMarketing.ajaxNormal(
    '/pad_marketing/notesCount/getNotesCount.action',{},
    function(data) {
    	console.log(data);
       if(data != ""){
    	   if(data.newPro > 0){
        	   $(".xywzh").append('<label class="tag tag_1">'+data.newPro+'</label>');			//新业务照会
    	   }
    	   if(data.mainten > 0){
    		   $(".bqzh").append('<label class="tag tag_2">'+data.mainten+'</label>');			//保全照会
    	   }
           if(data.returnVisit > 0){
        	   $(".xdhfzh").append('<label class="tag tag_3">'+data.returnVisit+'</label>');	//新单回访照会
           }
           if(data.claim > 0){
        	   $(".lpzh").append('<label class="tag tag_4">'+data.claim+'</label>');			//理赔照会
           }
           if(data.quality > 0){
        	   $(".zjzh").append('<label class="tag tag_5">'+data.quality+'</label>');			//质检照会
           }
           
       }else{
    	   return;
       }
    },
    function(data){},
    true,false)
    
}

//查询
function queryGoing(policeRefUrl){
	if(policeRefUrl !=null && policeRefUrl.toString().length>1){
		$("#policyNumber").val(policeRefUrl);
		var policyNumber = $("#policyNumber").val();//保单号
	}else{
		var policyNumber = $("#policyNumber").val();//保单号
	}
	var PolicyHolder = $("#PolicyHolder").val();//投保人
	var CertificateNumber = $("#CertificateNumber").val();//投保人证件号码
	var typeId = $("#typeId").attr("value");//投保人证件类型
	if($("#labels").val() == "1"){
		//校验查询条件
		if(CertificateNumber != "" && typeId == ""){
			alertMsg("请选择证件类型");
			return;
		}
		if(typeId != "" && CertificateNumber == ""){
			alertMsg("请填写投保人证件号码");
			return;
		}
		var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;  
		if( CertificateNumber != "" && reg.test(CertificateNumber) == false && CertificateNumber != undefined && $("#typeId").val() == "National ID"){  
		   alertMsg("请输入正确的身份证号码");
		   return;   
		}
		var jsonParam={};
		jsonParam.policyRef = policyNumber;			//保单号
		jsonParam.phName = PolicyHolder; 			//投保人
		jsonParam.cardType = typeId; 				//证件类型
		jsonParam.cardCode = CertificateNumber; 	//证件号码
		padMarketing.ajaxNormal(
				'/pad_marketing/notes/getMyNoteList.action',jsonParam,
				function(data) {
					console.log(data)
					if(data == "" || data == null || data == undefined){
						htmlNull(); 
					}else{
						$("#tableSort tr:gt(0)").remove(); 									//查询前清空数据
						thisUrl = window.document.location.pathname;						//当前URL
						
						var htmlLp='';
						for(var i=0;i<data.length;i++){
							htmlLp+='<tr id="dataAll" data=\''+JSON.stringify(data[i])+'\'>';
							htmlLp+='<td>'+data[i].POLICY_REF+'</td>';                      //保单号
							htmlLp+='<td>'+data[i].PH_NAME+'</td>';							//投保人
							htmlLp+='<td>'+data[i].PRODUCT_CODE+'</td>';					//主险代码
							var date=new Date(data[i].DUE_DATE);							//回复截止日期↓
							if(data[i].DUE_DATE){
								htmlLp+='<td>'+date.getFullYear()+"-"+parseInt(date.getMonth()+1)+"-"+date.getDate()+'</td>'; 
							}else{
								htmlLp+='<td>-</td>'; 
							}
							htmlLp+='<td><a onClick="sessionData(this)"><span class="icon icon-circle-xin"></span></a></td>';
							htmlLp+='</tr>';
						}
						$("#tableSort tbody").append(htmlLp);
						$("#demanded").parent().removeClass('hide');
						$("#demanded").text(data.length);
						noData();			//无数据显示空白
						if(myScroll){
							myScroll.refresh(); //刷新页面
						}
						
						
						
					}
					
					
				},
				function(data) {},//调用失败结果
				true,
				true,
				'好久没来，照会堆积如山啦！');

		//升序降序重置
		$(".primary th").find(".icon_1").text("↑");
	}
	if($("#labels").val() == "2"){

		//校验查询条件
		if(CertificateNumber != "" && typeId == ""){
			alertMsg("请选择证件类型");
			return;
		}
		if(typeId != "" && CertificateNumber == ""){
			alertMsg("请填写投保人证件号码");
			return;
		}
		var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;  
		if( CertificateNumber != "" && reg.test(CertificateNumber) == false && CertificateNumber != undefined && $("#typeId").val() == "National ID"){  
		   alertMsg("请输入正确的身份证号码");
		   return;   
		}
		var jsonParam={};
		jsonParam.policyRef = policyNumber; 					//保单号
		jsonParam.phName = PolicyHolder; 						//投保人
		jsonParam.cardType = typeId; 							//证件类型
		jsonParam.cardCode = CertificateNumber; 				//证件号码
		padMarketing.ajaxNormal(
		'/pad_marketing/notes/getPosList.action',jsonParam,
		function(data) {
			console.log(data)
			if(data == "" || data == null || data == undefined){
				htmlNull();
			}else{
				$("#tableSort tr:gt(0)").remove(); //查询前清空数据
				var htmlLp='';
				for(var i=0;i<data.length;i++){
					htmlLp+='<tr id="dataAll" data=\''+JSON.stringify(data[i])+'\'>';
					if(data[i].REMINDER){
						htmlLp+='<td><b style="color:red;">[催]</b>' + data[i].POLICY_REF+'</td>';
					}else{
						htmlLp+='<td>'+data[i].POLICY_REF+'</td>';			//保单号
					}
					htmlLp+='<td>'+data[i].PH_NAME+'</td>';				//投保人
					htmlLp+='<td>'+data[i].COVER_CODE+'</td>';			//主险代码
					var date=new Date(data[i].OVER_DATE);				//回复截止日期
					if(data[i].OVER_DATE){
						htmlLp+='<td>'+date.getFullYear()+"-"+parseInt(date.getMonth()+1)+"-"+date.getDate()+'</td>';	//回复截止日期
					}else{
						htmlLp+='<td>-</td>';	//回复截止日期
					}
					htmlLp+='<td>'+data[i].TASK_NO+'</td>';				//照会主任务号
					htmlLp+='<td>'+data[i].MOVEMENTS+'</td>';			//照会子任务号
					htmlLp+='<td><a onClick="goNewPdf2(this)"><span class="icon icon-circle-bian"></span></a></td>';
					htmlLp+='</tr>';
				}
				$("#tableSort tbody").append(htmlLp);
				$("#demanded").parent().removeClass('hide');
				$("#demanded").text(data.length);
				noData();									//无数据显示空白
				if(myScroll){
					myScroll.refresh(); //刷新页面
				}
				
			}
			
		},
		function(data) {},//调用失败结果
		true,
		true,
		'好久没来，照会堆积如山啦！');
		
		//升序降序重置
		$(".primary th").find(".icon_1").text("↑");
	
	}
	if($("#labels").val() == "3"){

		//校验查询条件
		if(CertificateNumber != "" && typeId == ""){
			alertMsg("请选择证件类型");
			return;
		}
		if(typeId != "" && CertificateNumber == ""){
			alertMsg("请填写投保人证件号码");
			return;
		}
		var reg = /\d{15}|\d{17}[0-9Xx]/;  
		if( CertificateNumber != "" && reg.test(CertificateNumber) == false && CertificateNumber != undefined && $("#typeId").val() == "National ID"){  
		   alertMsg("请输入正确的身份证号码");
		   return;   
		}
		
		var jsonParam={};
		jsonParam.policyRef = policyNumber; 										//保单号
		jsonParam.phName = PolicyHolder; 											//投保人
		jsonParam.cardType = typeId; 												//证件类型
		jsonParam.cardCode = CertificateNumber; 									//证件号码
		padMarketing.ajaxNormal(
		'/pad_marketing/notes/getMyNotesVisit.action',jsonParam,
		function(data) {
			console.log(data)
			if(data == "" || data == null || data == undefined){
				htmlNull();
			}else{
				$("#tableSort tr:gt(0)").remove();									//查询前清空数据
				var htmlLp='';
				for(var i=0;i<data.length;i++){
					htmlLp+='<tr id="dataAll" data=\''+JSON.stringify(data[i])+'\'>';
					htmlLp+='<td>'+data[i].POLICY_REF+'</td>';                      //保单号
					htmlLp+='<td>'+data[i].PH_NAME+'</td>';							//投保人
					htmlLp+='<td>'+data[i].PRODUCT_CODE+'</td>';					//主险代码
					var date=new Date(data[i].RC_DUE_DATE);							//回复截止日期
					if(data[i].RC_DUE_DATE){
						htmlLp+='<td>'+date.getFullYear()+"-"+parseInt(date.getMonth()+1)+"-"+date.getDate()+'</td>';	//回复截止日期
					}else{
						htmlLp+='<td>-</td>';	//回复截止日期
					}
					
					if(data[i].PROCESS_TYPE == "3"){
						htmlLp+='<td><a onClick="goNewPdf(this);"><span class="icon icon-circle-fang"></span></a></td>';
					}else{
						htmlLp+='<td></td>';
					}
					htmlLp+='</tr>';
				}
				$("#tableSort tbody").append(htmlLp);
				$("#demanded").parent().removeClass('hide');
				$("#demanded").text(data.length);
				noData();															//无数据显示空白
				if(myScroll){
					myScroll.refresh(); //刷新页面
				}
			}
			
		},
		function(data) {},//调用失败结果
		true,
		true,
		'好久没来，照会堆积如山啦！');
		
		//升序降序重置
		$(".primary th").find(".icon_1").text("↑");
		
	
	}

	if($("#labels").val() == "4"){

		var policyNumber = $("#policyNumber").val();								//保单号
		var PolicyHolder = $("#PolicyHolder").val();								//投保人
		var CertificateNumber = $("#CertificateNumber").val();						//投保人证件号码
		var typeId = $("#typeId").attr("value");									//投保人证件类型
		
		//校验查询条件
		if(CertificateNumber != "" && typeId == ""){
			alertMsg("请选择证件类型");
			return;
		}
		if(typeId != "" && CertificateNumber == ""){
			alertMsg("请填写投保人证件号码");
			return;
		}
		var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;  
		if( CertificateNumber != "" && reg.test(CertificateNumber) == false && CertificateNumber != undefined && $("#typeId").val() == "National ID"){  
		   alertMsg("请输入正确的身份证号码");
		   return;   
		}
		
		var jsonParam={};
		jsonParam.policyRef = policyNumber; 										//保单号
		jsonParam.phName = PolicyHolder; 											//投保人
		jsonParam.cardType = typeId; 												//证件类型
		jsonParam.cardCode = CertificateNumber; 									//证件号码
		padMarketing.ajaxNormal(
		'/pad_marketing/notes/getClaimList.action',jsonParam,
		function(data) {
			console.log(data)
			if(data == "" || data == null || data == undefined){
				htmlNull();
			}else{
				$("#tableSort tr:gt(0)").remove(); 									//查询前清空数据
				var htmlLp='';
				for(var i=0;i<data.length;i++){
					htmlLp+='<tr id="dataAll" data=\''+JSON.stringify(data[i])+'\'>';
					htmlLp+='<td>'+data[i].POLICY_REF+'</td>';                      //保单号
					htmlLp+='<td>'+data[i].CLAIM_ID+'</td>';						//理赔号
					htmlLp+='<td>'+data[i].PH_NAME+'</td>';							//投保人
					htmlLp+='<td>'+data[i].PRODUCT_CODE+'</td>';					//主险代码
					var date=new Date(data[i].DUE_DATE);							//回复截止日期
					if(data[i].DUE_DATE){
						htmlLp+='<td>'+date.getFullYear()+"-"+parseInt(date.getMonth()+1)+"-"+date.getDate()+'</td>';
					}else{
						htmlLp+='<td>-</td>';
					}
						
					htmlLp+='<td><a onClick="goNewPdf2(this);"><span class="icon icon-circle-pei"></span></a></td>';
					htmlLp+='</tr>';
					
				}
				$("#tableSort tbody").append(htmlLp);
				$("#demanded").parent().removeClass('hide');
				$("#demanded").text(data.length);
				noData();									//无数据显示空白
				if(myScroll){
					myScroll.refresh(); //刷新页面
				}
				
			}
		},
		function(data) {},//调用失败结果
		true,
		true,
		'好久没来，照会堆积如山啦！');
		
		//升序降序重置
		$(".primary th").find(".icon_1").text("↑");
	
	}

	if($("#labels").val() == "5"){


		var policyNumber = $("#policyNumber").val();								//保单号
		var PolicyHolder = $("#PolicyHolder").val();								//投保人
		var CertificateNumber = $("#CertificateNumber").val();						//投保人证件号码
		var typeId = $("#typeId").attr("value");									//投保人证件类型
		
		//校验查询条件
		if(CertificateNumber != "" && typeId == ""){
			alertMsg("请选择证件类型");
			return;
		}
		if(typeId != "" && CertificateNumber == ""){
			alertMsg("请填写投保人证件号码");
			return;
		}
		var reg = /(^\d{15}$)|(^\d{18}$)|(^\d{17}(\d|X|x)$)/;  
		if( CertificateNumber != "" && reg.test(CertificateNumber) == false && CertificateNumber != undefined && $("#typeId").val() == "National ID"){  
		   alertMsg("请输入正确的身份证号码");
		   return;   
		}
		
		var jsonParam={};
		jsonParam.policyRef = policyNumber; 		//保单号
		jsonParam.phName = PolicyHolder; 			//投保人
		jsonParam.cardType = typeId; 				//证件类型
		jsonParam.cardCode = CertificateNumber; 	//证件号码
		padMarketing.ajaxNormal(
		'/pad_marketing/notes/getQualityList.action',jsonParam,
		function(data) {
			console.log(data)
			if(data == "" || data == null || data == undefined){
				var htmlNull = '';
				htmlNull+='<tr class="noFind">';
				htmlNull+='<td colspan="7">暂无符合条件的查询</td>';
				htmlNull+='</tr>';
				$("#tableSort tbody tr").remove();
				$("#tableSort tbody").append(htmlNull);
			}else{
				$("#tableSort tr:gt(0)").remove(); //查询前清空数据
				var htmlLp='';
				thisUrl = window.document.location.pathname;														//当前URL
				var contractIdList = [];
				
				for(var c=0;c<data.length;c++){
					contractIdList.push(data[c].CONTRACT_ID);
				}
				//CONTRACT_ID合集筛选质检照会
				padMarketing.ajaxNormal("/pad_marketing/qualityCheck/checkContractId.action",{"contractIdList":contractIdList},
					function(result){
						 contractIds = result.contractId;
						var htmlLp='';
						for(var i=0;i<data.length;i++){
							htmlLp+='<tr id="dataAll" data=\''+JSON.stringify(data[i])+'\'>';
							htmlLp+='<td>'+data[i].POLICY_REF+'</td>';                      								//保单号
							htmlLp+='<td>'+data[i].PH_NAME+'</td>';															//投保人
							htmlLp+='<td>'+data[i].PRODUCT_CODE+'</td>';													//主险代码
							var date=new Date(data[i].DUE_TIME);															//回复截止日期
							if(data[i].DUE_TIME){
								htmlLp+='<td>'+date.getFullYear()+"-"+parseInt(date.getMonth()+1)+"-"+date.getDate()+'</td>';
							}else{
								htmlLp+='<td>-</td>';
							}
							
							var flag=1;
							for(t=0;t<contractIds.length;t++){
								if(contractIds[t]){
									if(data[i].CONTRACT_ID == contractIds[t].contractId){
										if(contractIds[t].allOk=="Y"){
											flag=2;
										}
									}
								}
							}
							if(flag==2){
								htmlLp+='<td>照会回复已提交</td>';
							}else{
								htmlLp+='<td><a onClick="sessionData(this);"><span class="icon icon-circle-zhi"></span></a></td>';
							}
							htmlLp+='</tr>';
						}
						$("#tableSort tbody").append(htmlLp);
						$("#demanded").parent().removeClass('hide');
						$("#demanded").text(data.length);
						noData();			//无数据显示空白
						if(myScroll){
							myScroll.refresh(); //刷新页面
						}
					});
				
			}
			
		},
		function(data) {},//调用失败结果
		true,
		true,
		'好久没来，照会堆积如山啦！');
		
		//升序降序重置
		$(".primary th").find(".icon_1").text("↑");
	
	}
	
}

//获取url参数     调用方法GetQueryString("参数名1");
function GetQueryString(name){
     var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
     var r = window.location.search.substr(1).match(reg);
     if(r!=null)return  unescape(r[2]); return null;
}

